from PySide6.QtWidgets import QPushButton
from PySide6.QtCore import Signal, QSize, Qt
from components.base_component import DraggableComponent

class ButtonComponent(DraggableComponent):
    """按钮组件"""
    button_clicked = Signal(str)  # 按钮ID
    
    def __init__(self, component_id, text, parent=None):
        super().__init__(component_id, parent)
        self.title_label.setText(f"按钮: {component_id}")
        
        # 设置按钮的最小尺寸确保完整显示
        self.setMinimumSize(200, 140)
        
        # 确保内容区域足够大
        self.content.setMinimumHeight(80)
        
        # 添加按钮 - 增大按钮尺寸
        self.button = QPushButton(text)
        self.button.setMinimumSize(160, 60)
        self.button.setStyleSheet("""
            QPushButton {
                font-size: 14px;
                font-weight: bold;
                padding: 10px;
                background-color: #0078d7;
                color: white;
                border-radius: 5px;
                border: none;
                margin: 5px;
            }
            QPushButton:hover {
                background-color: #1089e8;
            }
            QPushButton:pressed {
                background-color: #005fa3;
            }
        """)
        self.button.setCursor(Qt.CursorShape.PointingHandCursor)
        self.button.clicked.connect(self._on_button_clicked)
        self.content_layout.addWidget(self.button)
    
    def _on_button_clicked(self):
        """按钮点击处理函数"""
        print(f"ButtonComponent: 按钮 {self.component_id} 被点击")
        self.button_clicked.emit(self.component_id)
    
    def sizeHint(self):
        """提供按钮组件的默认尺寸建议"""
        return QSize(200, 140) 